<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="login_content/css/main.css">
    </head>
     <body class="um-vp bc-bg" ontouchstart>
        <div class="ub ub-ver uinn-a3 ub-fv">
            <div class="ub ub-ver uinn uinn-at1">
                <form method="post" action="http://whynothappy.sinaapp.com/">
                    <div class="umar-a uba bc-border c-wh">
                        <div class="ub ub-ac ubb umh5 bc-border ">
                            <div class=" uinput ub ub-f1">
                                <div class="uinn fa fa-user sc-text"></div>
                                <input placeholder="手机/邮箱/用户名" type="text" class="ub-f1" id = "user">
                            </div>
                        </div>
                        <div class="ub ub-ac umh5 bc-border ">
                            <div class=" uinput ub ub-f1">
                                <div class="uinn fa fa-lock sc-text"></div>
                                <input placeholder="密码" type="password" class="umw4 ub-f1" id="pass">

                            </div>
                        </div>
                    </div>
                    <div class="ub ub-ver">
                        <div class="uinn-at1">
                            <div class="btn ub ub-ac bc-text-head ub-pc bc-btn uc-a1" id="submit1">
                                登录
                            </div>
                        </div>
                    </div>
                    <button type="submit"class="uinvisible"></button>
                </form>

            </div>

        </div>
        <script src="js/appcan.js"></script>
        <script src="js/appcan.control.js"></script>
    </body>
    <script>
        appcan.ready(function() {
            appcan.initBounce();
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/get_buildings',
                data : {},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    if (data.state == 0)
                    {
                        init_building(data.buildings);
                    }
                },
                error:function(){
                    alert("fuck");
                }
            })
        })
        var arrData = [];
        function init_building(buildings)
        {
            var len = buildings.length;
            for(var i = 0; i < len; ++i)
            {
                arrData.push({
                    "title" : buildings[i].name,
                    "id" : buildings[i].id,
                    "louzhang" : buildings[i].louzhang,
                });
            }
            localStorage.setItem('buildings',arrData);
        }
        appcan.button("#submit1", "ani-act", function() {
            var user = $('#user')[0].value; 
            var pass = $('#pass')[0].value; 
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/login',
                data : {username : user , password : pass},
                contentType: 'application/json',
                success:function(data){
                    data = eval("(" + data + ")");
                    if (data.state == 0)
                    {
                        localStorage.setItem('username',user);
                        localStorage.setItem('password',pass);
                        localStorage.setItem('login',1);
                        var len = arrData.length;
                        for(var i = 0; i < len; ++i) if (arrData[i].louzhang == user)
                        {
                            localStorage.setItem('build_id', arrData[i].id);
                            localStorage.setItem('build_name', arrData[i].title);
                            break;
                        }
                        appcan.openWinWithUrl('catalog', 'info.html');
                    } else
                    alert("密码错误");
                },
                error:function(){
                    alert("fuck");
                }
            })
        })
    </script>
</html>